package com.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.dao.BaseDAO;
import com.entity.*;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class VisitAction extends ActionSupport {
	Visit data;
	BaseDAO dao = new BaseDAO();

	public String add() {
		data.setState("来访");
		data.setCurtime(new Date());
		dao.add(data);
		return show();
	}

	public String del() {
		dao.del(data);
		return show();
	}

	public String show() {
		ActionContext.getContext().put("all", dao.show("from Visit"));
		return SUCCESS;
	}
	

	
    public String exit(){
    	Visit obj = (Visit)dao.findByID(Visit.class,data.getId());
    	obj.setState("离开");
    	dao.update(obj);
    	return show();
    }
    

	public String update() {
		dao.update(data);
		return show();
	}

	
	
	
	
	public String find() {
		String hql = "from Visit where 1=1";
		List params = new ArrayList();
		
		
		if(!"".equals(data.getCurtime())){
			hql+=" and curtime=?";
			params.add(data.getCurtime());
		}
		
		ActionContext.getContext().put("all", dao.find(hql, params.toArray()));
		return "show";
	}

	public Visit getData() {
		return data;
	}

	public void setData(Visit data) {
		this.data = data;
	}


}
